<?php
/**
* @version $Id: mod_ohabolana.php 57 2009-05-09 08:39:50Z heriniaina.eugene $
* @package Joomla_1.0.0
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

$option = trim( mosGetParam( $_REQUEST, 'option', null ) );
$task = trim( mosGetParam( $_REQUEST, 'task', null ) );
$id = intval( mosGetParam( $_REQUEST, 'id', null ) );

global $mosConfig_cachepath;
global $mosConfig_live_site;


// use cache if available

require_once( $mosConfig_absolute_path . '/includes/Cache/Lite.php' );

$ohabolana_apikey =  $params->def('ohabolana_apikey', 'TEST KEY');
$ohabolana_filter =  $params->get('ohabolana_filter');

if($ohabolana_apikey) {
	// set some variables
	$mod_ohabolana_cache_options = array(
		'cacheDir' => $mosConfig_cachepath . '/',
		'lifeTime' => 86400
	);
	// create a Cache_Lite object
	$mod_ohabolana_cache_obj = new Cache_Lite($mod_ohabolana_cache_options);
	$mod_ohabolana_cache_id =  md5($ohabolana_apikey . $ohabolana_filter);

	$content = "";

	if ($content = $mod_ohabolana_cache_obj->get($mod_ohabolana_cache_id)) {
		$content .= "\n<!-- cached " . date("d/m/Y H:i:s") . " -->";
	} else {
		if (!class_exists('soapclient')) require_once('mod_ohabolana/nusoap.php');

		$client = new soapclient('http://serasera.org/ws/ohabolana/index.php?wsdl', true);
		$err = $client->getError();
		if ($err) {
			$content = $err ;
		}

		$ohParam = array('wsid' => $mosConfig_live_site, 'filter' => $ohabolana_filter);
		$result = $client->call('getQuote', $ohParam);

		// Check for a fault
		if ($client->fault) {
			foreach($result as $key=>$val) {
				$content .= $key . " -> " . $val . " <br />\n";
			}

		} else {
			// Check for errors
			$err = $client->getError();
			if ($err) {
				// Display the error
				$content .=  $err ;
			} else {
				// Display the result
				$content = $result;
				$mod_ohabolana_cache_obj->save($content, $mod_ohabolana_cache_id);
			}
		}
	}
	
}

?>